// 生成容器
function createDom(template) {
    if (template) {
        let wrapper = document.createElement('div');
        wrapper.innerHTML = template;
        return wrapper.childNodes;
    }
    else {
        console.error(`缺少template参数。`);
    }
}
// 主程序
function download(url, name = '下载') {
    if (!url) {
        return;
    }
    if (url != 'string') {
        let dataUrl = window.URL.createObjectURL(new Blob([url]));
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = dataUrl;
        link.setAttribute("download", name + ".xls");
        document.body.appendChild(link);
        link.click();
        return;
    }
    let container = document.querySelector('#dIframe');
    if (!container) {
        container = createDom(`<iframe src="" frameborder="0" id="dIframe"></iframe>`)[0];
        let body = document.querySelector('body');
        body.appendChild(container);
    }
    return new Promise((reso, rej) => {
        container.onerror = function (e) {
            console.error(e);
            rej(e);
        };
        container.src = url;
        reso(true);
    });
}
export { createDom, download };
export default download;
